package ${Data.templateModel.savePath};

<#list Data.importList?keys as key>
import ${Data.importList[key]};
</#list>	

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.controller.base.BaseController;
import com.zkingsoft.entity.Page;
import com.zkingsoft.util.PageData;

/**
 * This field was generated by Zking.software.Codegen.
 * @date ${Data.variables.now}
 */
@Controller
@RequestMapping(value = "/${Data.tableClassModel.classVariableName}")
public class ${Data.tableClassModel.className}Controller extends BaseController{

	@Resource
	private ${Data.tableClassModel.className}Service ${Data.tableClassModel.classVariableName}Service;
	
	/**
	 * 列表显示
	 */
   	@RequestMapping(value="/list")
	public @ResponseBody Page list(Page page) throws Exception{
		PageData pd = this.getPageData();
		page.setPd(pd);
		
		List rows = ${Data.tableClassModel.classVariableName}Service.list(page);
		
		page.setLists(rows);
		return page;
	}
   	
   	
	/**
	 * 新增或者修改页面
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(${Data.tableClassModel.className} ${Data.tableClassModel.classVariableName}) {
		if (${Data.tableClassModel.classVariableName}.get${Data.tableClassModel.primaryKey.methodName}() != null) {
			return modify(${Data.tableClassModel.classVariableName}Service, ${Data.tableClassModel.classVariableName}, "${Data.tableClassModel.classVariableName}");
		} else {
			return add(${Data.tableClassModel.classVariableName}Service, ${Data.tableClassModel.classVariableName}, "${Data.tableClassModel.classVariableName}");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
	@SaveRequestToken
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		${Data.tableClassModel.className} ${Data.tableClassModel.classVariableName};
		if (id != null) {
			${Data.tableClassModel.classVariableName} = ${Data.tableClassModel.classVariableName}Service.findById(id);
			WebUtil.getRequest().setAttribute("obj", ${Data.tableClassModel.classVariableName});
		}
		return "admin/${Data.tableClassModel.classVariableName}-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(${Data.tableClassModel.classVariableName}Service, keys);
	}
  
}